<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>自定义表单导入</title>
    <#include "/pubHeadStyleTree.html">
</head>
<body>
<div style="position: relative;height: 100%;">
<div class="ccpui-trees">
            <p class="isShowTree colorSwitch">
                <span style="float: left;color: white">&nbsp;&nbsp;组织机构管理</span>
                <!--<i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>-->
            </p>
            <div style="margin-top: 6px;">
                <ul class="ccpui-iconTree iconTrees">
                    <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                    <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                    <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                    <input type="text" style="width: 50%" class="resZtreeValue">
                </ul>
                <ul id="treeSelectOrg" class="ztree ccpui-listZtree"></ul>
            </div>
</div>
    <div class="ccpui-coreContent">
        <div class="layui-form-item">
            <div class="layui-upload-drag" id="xmlFile" style="text-align: center;margin: 90px">
                <i class="layui-icon"></i>
                <p>点击上传，或将文件拖拽到此处</p>
            </div>
        </div>
        <div class="layui-btn-container" style="bottom: 0;position: absolute;text-align: center;left:38%">
            <button class="layui-btn layui-btn-sm" id="importButton">
                <span>导入</span>
            </button>
            <a class="layui-btn layui-btn-sm layui-btn-danger" id="return">
                <span>取消</span>
            </a>
        </div>
    </div>
</div>
<script>
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer','setter','upload','jquery','commons'], function() {
        var layer = layui.layer,
            $ = layui.jquery,
            setter = layui.setter,
            upload=layui.upload,
            commons=layui.commons;
        var index = parent.layer.getFrameIndex(window.name);
        $('#return').click(function () {
            parent.layer.close(index);
        });
        //选中的左侧角色树的节点ID
        var selectOrgId = "";
        var tenantId = "";
        //文件上传
        upload.render({
            elem: '#xmlFile'
            ,url: serverPath.formPath + setter.formLinkPath +'formDef/importXml'
            ,accept: 'file'
            ,auto: false //选择文件后不自动上传
            , multiple: true
            ,bindAction: '#importButton' //指向一个按钮触发上传
            , data: {
                tenantId: function(){
                    return tenantId;
                }
            }
            , before: function (obj) {
                if(tenantId!==""){
                    $("input.layui-upload-file").after('<input type="hidden" name="tenantId" value="'+tenantId+'"/>');
                }
            }
            ,done: function(res){
                if(!commons._filterRecord(res)){
                    layer.alert(res.msg);
                    $(".layui-upload-choose").text("");
                }else{
                    layer.alert(res.msg,{skin: 'btn-class'}, function () {
                        parent.layui.table.reload('customForm', {
                            page: {
                                curr: 1
                            }
                        });
                        parent.layui.totalFilter.init('customForm');
                        commons._bulletWindow(index);
                    });
                }
            }
        });

        //树状结构
        orgZtree();
        function orgZtree(){
            $.ajax({
                url: serverPath.formPath + setter.sysLinkPath +"sysOrg/list",
                type: "get",
                contentType: 'application/json',
                dataType: 'json',
                success: function(data) {
                    var zNodes = data.data;
                    var setting = {
                        view: {
                            showLine: false,
                            nameIsHTML: true, //允许name支持html
                            selectedMulti: false
                        },
                        edit: {
                            enable: false,
                            editNameSelectAll: false
                        },
                        data: {
                            simpleData: {
                                enable: true,
                                idKey:"orgId",
                                pIdKey:"orgSupId"
                            }
                        },
                        callback: {
                            onClick: onClickUsers,
                        }
                    };
                    $.fn.zTree.init($('#treeSelectOrg'), setting, zNodes);
                    component.fuzzySearch('treeSelectOrg','.resZtreeValue',null,true); //初始化模糊搜索方法
                }
            });
        }

        function onClickUsers(event, treeId, treeNode, clickFlag) {
            selectOrgId = treeNode.orgId;
            $.ajax({
                url: serverPath.formPath +'/out/getTenIdByOrgId',
                type: "post",
                data: {"orgId": selectOrgId},
                success: function (result) {
                    tenantId = result;
                }
            });
        }

        function showRMenu( x, y) {
            $("#orgRightMenu ul").show();
            x+=15;
            y+=10;
            $("#orgRightMenu").css({"top":y+"px", "left":x+"px", "visibility":"visible"});

            $("body").bind("mousedown", onBodyMouseDown);
        }
        function hideRMenu() {
            if ($("#orgRightMenu")) $("#orgRightMenu").css({"visibility": "hidden"});
            $("body").unbind("mousedown", onBodyMouseDown);
        }
        function onBodyMouseDown(event){
            if (!(event.target.id == "orgRightMenu" || $(event.target).parents("#orgRightMenu").length>0)) {
                $("#orgRightMenu").css({"visibility" : "hidden"});
            }
        }

        //展开
        $(".iconTrees .zTree-triangle-d").click(function() {
            $.fn.zTree.getZTreeObj("treeSelectOrg").expandAll(true);
        });
        //收起
        $(".iconTrees .zTree-triangle-r").click(function() {
            $.fn.zTree.getZTreeObj("treeSelectOrg").expandAll(false);
        });
        //刷新
        $(".iconTrees .zTree-refresh").click(function() {
            orgZtree();
        });

        //弹窗设置
        $('body > [name=configOrgDiv]').remove();
        $('body').append($('[name=configOrgDiv]'));
        $('body > div.orgSelect').remove();
        $('body').append($('div.orgSelect'));
        $('body > form.importUser-onfile').remove();
        $('body').append($('form.importUser-onfile'));


        //树状菜单隐藏
        var isOrg = true;
        $(".treeone").click(function () {
            isOrg = tresStyle(isOrg, ".treeone");
        });
    });
</script>
<style>
    .layui-form-item .layui-inline{
        position: absolute;
        bottom:42%;
        left:22%;
    }
    .ccpui-coreContent .layui-form-item .layui-upload-form{
        margin-top: 100px;
    }
</style>
</body>
</html>